<%--
  Created by IntelliJ IDEA.
  User: ZTK
  Date: 2025/6/15
  Time: 23:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>订单详情 - 二手平台</title>
    <link href="${pageContext.request.contextPath}/resources/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/bootstrap-icons.css">
    <style>
        body {
            background-color: #f8f9fa;
            padding-top: 70px;
        }
        .order-container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
            padding: 25px;
            margin-bottom: 30px;
        }
        .order-header {
            border-bottom: 2px solid #f1f1f1;
            padding-bottom: 15px;
            margin-bottom: 20px;
        }
        .order-info {
            background-color: #f9f9f9;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 25px;
        }
        .info-item {
            display: flex;
            margin-bottom: 12px;
        }
        .info-label {
            width: 120px;
            font-weight: 600;
            color: #6c757d;
        }
        .order-item {
            display: flex;
            align-items: center;
            padding: 15px 0;
            border-bottom: 1px solid #f1f1f1;
        }
        .order-item-image {
            width: 100px;
            height: 100px;
            object-fit: cover;
            border-radius: 5px;
            margin-right: 20px;
        }
        .btn-pay {
            background-color: #28a745;
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 5px;
            font-weight: 600;
            width: 200px;
            margin: 30px auto;
            display: block;
            transition: background-color 0.3s;
        }
        .btn-pay:hover {
            background-color: #218838;
        }
        .total-amount {
            font-size: 20px;
            font-weight: 700;
            color: #ff6b6b;
            text-align: right;
            margin-top: 20px;
        }
        .status-badge {
            padding: 5px 10px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 600;
        }
        .status-pending {
            background-color: #ffc107;
            color: #333;
        }
        .status-paid {
            background-color: #28a745;
            color: white;
        }

        .navbar{
            background-color: #ff5000;
        }
        .navbar-brand{
            font-size: 20px;
            color: white !important;
            font-weight: bold;
        }
    </style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg fixed-top">
    <div class="container">
        <a class="navbar-brand" href="${pageContext.request.contextPath}/product/list">二手平台</a>
        <div class="d-flex flex-grow-1 justify-content-center">
            <div class="text-white fw-bold">订单详情</div>
        </div>
        <ul class="navbar-nav">
            <c:choose>
                <c:when test="${not empty sessionScope.currentUser}">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                                ${sessionScope.currentUser.username}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="${pageContext.request.contextPath}/order/list">我的订单</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="${pageContext.request.contextPath}/user/logout">退出登录</a></li>
                        </ul>
                    </li>
                </c:when>
                <c:otherwise>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath}/user/login">登录</a>
                    </li>
                </c:otherwise>
            </c:choose>
        </ul>
    </div>
</nav>

<div class="container">
    <div class="order-container">
        <div class="order-header d-flex justify-content-between align-items-center">
            <h4>订单号: ${order.id}</h4>
            <span class="status-badge status-${order.status == '待支付' ? 'pending' : 'paid'}">
                ${order.status}
            </span>
        </div>

        <!-- 订单信息 -->
        <div class="order-info">
            <div class="info-item">
                <div class="info-label">收货人:</div>
                <div>${order.receiverName}</div>
            </div>
            <div class="info-item">
                <div class="info-label">联系电话:</div>
                <div>${order.receiverPhone}</div>
            </div>
            <div class="info-item">
                <div class="info-label">收货地址:</div>
                <div>${order.receiverAddress}</div>
            </div>
            <div class="info-item">
                <div class="info-label">下单时间:</div>
                <div><fmt:formatDate value="${order.createdTime}" pattern="yyyy-MM-dd HH:mm:ss" /></div>
            </div>
        </div>

        <!-- 商品列表 -->
        <h5>商品清单</h5>
        <c:forEach items="${order.orderItems}" var="item">
            <div class="order-item">
                <img src="${item.product.imagePath}" class="order-item-image" alt="${item.product.name}">
                <div class="flex-grow-1">
                    <h6>${item.product.name}</h6>
                    <div class="d-flex justify-content-between">
                        <div>单价: ¥<fmt:formatNumber value="${item.price}" pattern="#,##0.00" /></div>
                        <div>数量: ${item.quantity}</div>
                        <div>小计: ¥<fmt:formatNumber value="${item.price * item.quantity}" pattern="#,##0.00" /></div>
                    </div>
                </div>
            </div>
        </c:forEach>

        <div class="total-amount">
            合计: ¥<fmt:formatNumber value="${order.totalAmount}" pattern="#,##0.00" />
        </div>

        <c:if test="${order.status == '待支付'}">
            <form action="${pageContext.request.contextPath}/order/pay/${order.id}" method="post">
                <button type="submit" class="btn btn-pay">
                    <i class="bi bi-credit-card"></i> 立即支付
                </button>
            </form>
        </c:if>
    </div>
</div>

<script src="${pageContext.request.contextPath}/resources/js/jquery-3.6.0.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/js/popper.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/js/bootstrap.min.js"></script>
</body>
</html>
